<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>尚硅谷会员注册页面</title>
	<!-- 显示头部 -->
	<%@ include file="/pages/common/header.jsp" %>
	<style type="text/css">
		.login_form{
			height:420px;
			margin-top: 25px;
		}
		
	</style>

	<script type="text/javascript">
		$(function(){
			
			$("#mycode").click(function(){
				this.src="kaptcha.jpg?d=" + new Date();
			});
			
			$("#sub_btn").click(function(){
				var name = $("#username").val();
				var reg = /^\w{5,12}$/;
				if(!reg.test(name)){
					$(".errorMsg").text("用户名格式不正确");
					return false;
				}
				
				var password = $("#password").val();
				var reg2 = /^\w{5,12}$/;
				if(!reg2.test(password)){
					$(".errorMsg").text("密码格式不正确");
					return false;
				}
				
				var pw = $("#repwd").val();
				if(pw != password){
					$(".errorMsg").text("密码输入不一致");
					return false;
				}
				
				var email = $("#email").val();
				var reg3 = /^[a-z\d]+(\.[a-z\d]+)*@([\da-z](-[\da-z])?)+(\.{1,2}[a-z]+)+$/;
				if(!reg3.test(email)){
					$(".errorMsg").text("邮箱格式错误");
					return false;
				}
				
				var code = $.trim($("#code").val());
				if(code == ""){
					$(".errorMsg").text("验证码不能为空");
					return false;
				}
				return true;
			});
			
			$("#username").blur(function(){
				var username = this.value;
				$.getJSON("userServlet", "action=ajaxRegist&username="+username,function(data){
					if(data.existUsername){
						$("span.errorMsg").text("用户名已存在");
					}else if(username == ""){
						$("span.errorMsg").text("");
					}else{
						$("span.errorMsg").text("用户名可用");
					}
				});
			});
		});
	</script>
</head>
<body>
		<div id="login_header">
			<img class="logo_img" alt="" src="static/img/logo.gif" >
		</div>
		
			<div class="login_banner">
			
				<div id="l_content">
					<span class="login_word">欢迎注册</span>
				</div>
				
				<div id="content">
					<div class="login_form">
						<div class="login_box">
							<div class="tit">
								<h1>注册尚硅谷会员</h1>
								<span class="errorMsg">
									<%-- <%=request.getAttribute("msg")==null?"":request.getAttribute("msg") %> --%>
									${requestScope.msg}
								</span>
								
							</div>
							<div class="form">
								<form action="userServlet" method="post">
									<input type="hidden" name="action" value="regist"/>
									<label>用户名称：</label>
									<input class="itxt" type="text" placeholder="请输入用户名" autocomplete="off" tabindex="1" name="username" id="username"
									 	value="${requestScope.username}"
									 />
									<br />
									<br />
									<label>用户密码：</label>
									<input class="itxt" type="password" placeholder="请输入密码" autocomplete="off" tabindex="1" name="password" id="password" />
									<br />
									<br />
									<label>确认密码：</label>
									<input class="itxt" type="password" placeholder="确认密码" autocomplete="off" tabindex="1" name="repwd" id="repwd" />
									<br />
									<br />
									<label>电子邮件：</label>
									<input class="itxt" type="text" placeholder="请输入邮箱地址" autocomplete="off" tabindex="1" name="email" id="email" 
										value="${ requestScope.email }"
									/>
									<br />
									<br />
									<label>验证码：</label>
									<input class="itxt" type="text" style="width: 150px;" id="code" name="code"/>
									<span><img alt="" id="mycode" src="kaptcha.jpg" style="float: right; margin-right: 40px"></span>										
									<br />
									<br />
									<input type="submit" value="注册" id="sub_btn" />
									
								</form>
							</div>
							
						</div>
					</div>
				</div>
			</div>
		<!-- 显示页脚 -->
		<%@ include file="/pages/common/footer.jsp" %>
</body>
</html>